package com.itguigu.rabbitmq.two;

import com.itguigu.rabbitmq.utils.RabbitMqutil;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Date 2021/7/18 10:59
 * @Created by wangle
 * @Description 这是一个工作线程，相当于一个消费者
 */
public class Work01 {
    //队列名称
    public static final String QUEUE_NAME = "hello";

    //接受消息
    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqutil.getChannel();


        //声明 接受消息
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("接收到的消息：" + new String(message.getBody()));

        };

        //取消消息时的回调
        CancelCallback cancelCallback = (consumerTag) -> {

            System.out.println("消息消费被中断");
        };

        System.out.println("c2等待接收消息.....");
        //消息的接收
        /*
         * 消费者消息
         * 1.消费那个对列
         * 2.消费成功后是否要自动应答，true是自动应答，false是手动应答
         * 3.消费者未成功消费的回调
         * 4 .消费者取消消费的回调
         * */
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);

    }


}
